package xin.ryven.car.android

import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun testLrc() {
        val lrcText = """
            [00:00.00] 作词：李健
            [00:01.00] 作曲：李健
            """
        val lrcList = lrcText.trim().split("\n")
        val timeRegex = "\\[(\\d{2}):(\\d{2})\\.(\\d{2,3})](.*)".toRegex()

        val lrcEntryList = lrcList.map {
            val result = timeRegex.find(it)
            if (result != null) {
                val time =
                    result.groupValues[1].toInt() * 60 * 1000 + result.groupValues[2].toInt() * 1000 + result.groupValues[3].toInt()
                val text = result.groupValues[4]
                println("$time $text")
            } else {
                print(-1)
            }
        }
        assertNotNull(lrcEntryList)
    }
}